package com.servlet;

import dao.StudentDao;
import dao.impl.StudentDaoImpl;
import com.service.StudentService;
import com.service.impl.StudentServicelmpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/student")//注解
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String flag = request.getParameter("flag");
        StudentService service=new StudentServicelmpl();
        if (flag.equals("delete")) {
            String studentno = request.getParameter("studentno");
            StudentDao dao = new StudentDaoImpl();
            int id = Integer.parseInt(studentno);
            int count = dao.delete(id);
            if (count > 0) {
                response.sendRedirect("student");
            } else {
                response.sendRedirect("error.jsp");

            }
        }
    }
}
